Skip to content

[swc-plugin] Compile a "use step" function expression bound to a variable inside a function as a nested step - #5503

Merged
TooTallNate merged 1 commit into
mainfrom
codemod-for-steprun-to-use-step-migration-swc-named-fn-step
Nov 17, 2026
Merged

TooTallNate merged 1 commit into
mainfrom
codemod-for-steprun-to-use-step-migration-swc-named-fn-step

Conversation

@pranaygp

Copy link
Copy Markdown
Contributor

Summary

A "use step" function expression bound to a variable inside a workflow (or any other function) was compiled as a module-level step, so the run failed when it reached it:

export async function receiptWorkflow(n: number, label: string) {
  'use workflow';
  const send = async function () {
    'use step';
    return `${label}:${n}`;
  };
  return send(); // Step "step//./workflows/receipt//send" is not registered
}

The arrow form (const send = async () => { 'use step'; ... }) and a function declaration already worked.

Cause: in visit_mut_var_decl, the Expr::Fn step branch had no nested-scope check, unlike the Expr::Arrow branch next to it. As a result:

  • step mode emitted a registration for a binding that doesn't exist at module scope, so nothing was registered;
  • workflow mode called the un-namespaced step ID (…//send) without a closure-variable getter.

Fix: inside a function, this branch now takes the same path as the arrow form. The step is hoisted and namespaced by the enclosing function (receiptWorkflow/send), it gets the variables it captures, and the original function is kept with the directive stripped for direct calls. A step bound to a variable takes the variable's name, as it already did at module scope and for arrows. Module-level function expressions are unchanged.

Tests

  • New fixture (nested-step-function-expression): named and anonymous function expressions inside a workflow, one inside a plain helper function, and a module-level control. The step and workflow outputs agree on every step ID, which step_id_consistency checks. All 421 Rust tests pass, and existing fixture outputs are unchanged.
  • Runtime: the vitest workbench runs a workflow with a named and an anonymous function-expression step, both capturing workflow variables. On the previous plugin build it fails with Step "step//./workflows/nested-step-ids//named" is not registered; with this change it passes. The full vitest workbench passes (77 tests, plus one marked as an expected failure).
  • Spec: spec.md lists the nested-step forms and how each is named.

🤖 Generated with Claude Code

…le inside a function as a nested step

`const send = async function () { "use step"; ... }` inside a workflow (or
any function) took the module-level path in visit_mut_var_decl: step mode
registered nothing for it, and workflow mode called an un-namespaced step
ID without the closure variables, so the run failed with "Step ... is not
registered". It now takes the same path as the arrow form: hoisted,
namespaced by the enclosing function (`workflow/send`), and given the
variables it captures.

Adds a fixture for named and anonymous function expressions in a workflow
and in a plain helper (with a module-level control), a vitest workbench
runtime test that fails on the previous plugin, and a spec note.

Co-Authored-By: Claude <noreply@anthropic.com>

Co-Authored-By: Pranay Prakash <1797812+pranaygp@users.noreply.github.com>
@pranaygp
pranaygp requested a review from a team as a code owner November 17, 2026 16:15
Copilot AI balanced review requested due to automatic review settings November 17, 2026 16:15
@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
example-nextjs-workflow-turbopack Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
example-nextjs-workflow-webpack Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
example-workflow Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workbench-astro-workflow Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workbench-express-workflow Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workbench-fastify-workflow Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workbench-hono-workflow Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workbench-nestjs-workflow Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workbench-nitro-workflow Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workbench-nuxt-workflow Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workbench-python-workflow Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workbench-sveltekit-workflow Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workbench-tanstack-start-workflow Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workbench-vite-workflow Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workflow-docs Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workflow-swc-playground Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workflow-tarballs Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC
workflow-web Ready Ready Preview, v0 Nov 17, 2026 4:20pm UTC

@changeset-bot

changeset-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9384c7d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@workflow/swc-plugin Patch
@workflow/builders Patch
@workflow/nest Patch
@workflow/next Patch
@workflow/rollup Patch
@workflow/astro Patch
@workflow/cli Patch
@workflow/nitro Patch
@workflow/sveltekit Patch
@workflow/vite Patch
@workflow/vitest Patch
@workflow/world-cloudflare Patch
workflow Patch
@workflow/world-testing Patch
@workflow/nuxt Patch
@workflow/core Patch
@workflow/world-vercel Patch
@workflow/web-shared Patch
@workflow/web Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

✅ All tests passed

⚠️ Flaky E2E Tests (passed on retry)

These tests failed at least once and passed on a retry. A recurring entry here is a real race worth investigating.

  • awaitChildReturnValueWorkflow - parent waits on the child-run completion hook (fail: false) (nextjs-webpack · local-dev / local / node / canary)
  • awaitChildReturnValueWorkflow - parent waits on the child-run completion hook (fail: true) (nextjs-webpack · local-dev / local / node / canary)
  • fibonacciWorkflow - recursive workflow composition via start() (nextjs-webpack · local-dev / local / node / canary)
  • promiseRaceStressTestWorkflow (nextjs-webpack · local-dev / local / node / stable)
  • webhookWorkflow (vite · local-dev / local / quickjs / stable)
  • webhookWorkflow (nextjs-webpack · local-prod / local / node / canary)

🛠 Infra Events (absorbed by the harness)

Platform anomalies the e2e harness detected and worked around (e.g. a run the queue never picked up, replaced by a fresh run). Clustered timestamps indicate a backend blip; a steady drip indicates a platform issue worth escalating.

  • run-pickup-stall · runs app-generated source against a registered step (tanstack-start) · at 16:22:06Z · abandoned wrun_01M7N5149XTB8P4HZ1AH8VR627
  • cold-start-warmup · suite warmup (tanstack-start) · at 16:22:18Z · abandoned wrun_01M7N514B1SHCMGH271CRMBTE6
  • run-pickup-stall · ChainableService.processWithThis - static step methods using this to reference the class (vite) · at 16:23:17Z · abandoned wrun_01M7N53AB7XFHFKD4X4HAPV1GV
  • run-pickup-stall · ChainableService.processWithThis - static step methods using this to reference the class (nextjs-webpack) · at 16:26:35Z · abandoned wrun_01M7N59BNCBEY9BVRBABCSPVBA

E2E Test Summary

Summary
Passed Failed Skipped Total
✅ ▲ Vercel Production 4649 0 940 5589
✅ 💻 Local Development 5272 0 731 6003
✅ 📦 Local Production 5272 0 731 6003
✅ 🐘 Local Postgres 5417 0 586 6003
✅ 🪟 Windows 401 0 13 414
✅ 🌐 Cross-language Conformance 68 0 114 182
✅ dynamic-runs 0 0 0 0
✅ local-postgres-spec9 0 0 364 364
✅ local-spec9 409 0 5 414
✅ vercel-http-transport 1054 0 188 1242
✅ vercel-multi-region 27 0 0 27
✅ vercel-queue-hold 4 0 0 4
✅ vercel-spec9 395 0 19 414
✅ vercel-ws-transport 712 0 116 828
Total 23680 0 3807 27487
Details by Category

✅ ▲ Vercel Production

App Passed Failed Skipped
✅ astro-node 171 0 36
✅ astro-quickjs 170 0 37
✅ example-node 171 0 36
✅ example-quickjs 170 0 37
✅ express-node 171 0 36
✅ express-quickjs 170 0 37
✅ fastify-node 171 0 36
✅ fastify-quickjs 170 0 37
✅ hono-node 171 0 36
✅ hono-quickjs 170 0 37
✅ nest-node 171 0 36
✅ nest-quickjs 170 0 37
✅ nextjs-turbopack-node 199 0 8
✅ nextjs-turbopack-quickjs 198 0 9
✅ nextjs-webpack-node 199 0 8
✅ nextjs-webpack-quickjs 198 0 9
✅ nitro-node 171 0 36
✅ nitro-quickjs 170 0 37
✅ nuxt-node 171 0 36
✅ nuxt-quickjs 170 0 37
✅ python-node 66 0 141
✅ sveltekit-node 190 0 17
✅ sveltekit-quickjs 189 0 18
✅ tanstack-start-node 171 0 36
✅ tanstack-start-quickjs 170 0 37
✅ vite-node 171 0 36
✅ vite-quickjs 170 0 37

✅ 💻 Local Development

App Passed Failed Skipped
✅ astro-stable-node 172 0 35
✅ astro-stable-quickjs 171 0 36
✅ express-stable-node 172 0 35
✅ express-stable-quickjs 171 0 36
✅ fastify-stable-node 172 0 35
✅ fastify-stable-quickjs 171 0 36
✅ hono-stable-node 172 0 35
✅ hono-stable-quickjs 171 0 36
✅ nest-stable-node 172 0 35
✅ nest-stable-quickjs 171 0 36
✅ nextjs-turbopack-canary-node 201 0 6
✅ nextjs-turbopack-canary-quickjs 200 0 7
✅ nextjs-turbopack-quickjs-snapshot 200 0 7
✅ nextjs-turbopack-stable-node 201 0 6
✅ nextjs-turbopack-stable-quickjs 200 0 7
✅ nextjs-webpack-canary-node 201 0 6
✅ nextjs-webpack-canary-quickjs 200 0 7
✅ nextjs-webpack-stable-node 201 0 6
✅ nextjs-webpack-stable-quickjs 200 0 7
✅ nitro-stable-node 172 0 35
✅ nitro-stable-quickjs 171 0 36
✅ nuxt-stable-node 172 0 35
✅ nuxt-stable-quickjs 171 0 36
✅ sveltekit-stable-node 191 0 16
✅ sveltekit-stable-quickjs 190 0 17
✅ tanstack-start-node 172 0 35
✅ tanstack-start-quickjs 171 0 36
✅ vite-stable-node 172 0 35
✅ vite-stable-quickjs 171 0 36

✅ 📦 Local Production

App Passed Failed Skipped
✅ astro-stable-node 172 0 35
✅ astro-stable-quickjs 171 0 36
✅ express-stable-node 172 0 35
✅ express-stable-quickjs 171 0 36
✅ fastify-stable-node 172 0 35
✅ fastify-stable-quickjs 171 0 36
✅ hono-stable-node 172 0 35
✅ hono-stable-quickjs 171 0 36
✅ nest-stable-node 172 0 35
✅ nest-stable-quickjs 171 0 36
✅ nextjs-turbopack-canary-node 201 0 6
✅ nextjs-turbopack-canary-quickjs 200 0 7
✅ nextjs-turbopack-quickjs-snapshot 200 0 7
✅ nextjs-turbopack-stable-node 201 0 6
✅ nextjs-turbopack-stable-quickjs 200 0 7
✅ nextjs-webpack-canary-node 201 0 6
✅ nextjs-webpack-canary-quickjs 200 0 7
✅ nextjs-webpack-stable-node 201 0 6
✅ nextjs-webpack-stable-quickjs 200 0 7
✅ nitro-stable-node 172 0 35
✅ nitro-stable-quickjs 171 0 36
✅ nuxt-stable-node 172 0 35
✅ nuxt-stable-quickjs 171 0 36
✅ sveltekit-stable-node 191 0 16
✅ sveltekit-stable-quickjs 190 0 17
✅ tanstack-start-node 172 0 35
✅ tanstack-start-quickjs 171 0 36
✅ vite-stable-node 172 0 35
✅ vite-stable-quickjs 171 0 36

✅ 🐘 Local Postgres

App Passed Failed Skipped
✅ astro-stable-node 177 0 30
✅ astro-stable-quickjs 176 0 31
✅ express-stable-node 177 0 30
✅ express-stable-quickjs 176 0 31
✅ fastify-stable-node 177 0 30
✅ fastify-stable-quickjs 176 0 31
✅ hono-stable-node 177 0 30
✅ hono-stable-quickjs 176 0 31
✅ nest-stable-node 177 0 30
✅ nest-stable-quickjs 176 0 31
✅ nextjs-turbopack-canary-node 206 0 1
✅ nextjs-turbopack-canary-quickjs 205 0 2
✅ nextjs-turbopack-quickjs-snapshot 205 0 2
✅ nextjs-turbopack-stable-node 206 0 1
✅ nextjs-turbopack-stable-quickjs 205 0 2
✅ nextjs-webpack-canary-node 206 0 1
✅ nextjs-webpack-canary-quickjs 205 0 2
✅ nextjs-webpack-stable-node 206 0 1
✅ nextjs-webpack-stable-quickjs 205 0 2
✅ nitro-stable-node 177 0 30
✅ nitro-stable-quickjs 176 0 31
✅ nuxt-stable-node 177 0 30
✅ nuxt-stable-quickjs 176 0 31
✅ sveltekit-stable-node 196 0 11
✅ sveltekit-stable-quickjs 195 0 12
✅ tanstack-start-node 177 0 30
✅ tanstack-start-quickjs 176 0 31
✅ vite-stable-node 177 0 30
✅ vite-stable-quickjs 176 0 31

✅ 🪟 Windows

App Passed Failed Skipped
✅ nextjs-turbopack-node 201 0 6
✅ nextjs-turbopack-quickjs 200 0 7

✅ 🌐 Cross-language Conformance

App Passed Failed Skipped
✅ python 68 0 114

✅ dynamic-runs

App Passed Failed Skipped
✅ astro-vercel 0 0 0
✅ example-vercel 0 0 0
✅ express-vercel 0 0 0
✅ fastify-vercel 0 0 0
✅ hono-vercel 0 0 0
✅ nest-vercel 0 0 0
✅ nextjs-turbopack-vercel 0 0 0
✅ nextjs-webpack-vercel 0 0 0
✅ nitro-vercel 0 0 0
✅ nuxt-vercel 0 0 0
✅ sveltekit-vercel 0 0 0
✅ tanstack-start-vercel 0 0 0
✅ vite-vercel 0 0 0

✅ local-postgres-spec9

App Passed Failed Skipped
✅ nextjs-turbopack-stable-node 0 0 182
✅ nextjs-turbopack-stable-quickjs 0 0 182

✅ local-spec9

App Passed Failed Skipped
✅ nextjs-turbopack-node 205 0 2
✅ nextjs-turbopack-quickjs 204 0 3

✅ vercel-http-transport

App Passed Failed Skipped
✅ example 171 0 36
✅ express 171 0 36
✅ hono 171 0 36
✅ nextjs-turbopack 199 0 8
✅ nitro 171 0 36
✅ vite 171 0 36

✅ vercel-multi-region

App Passed Failed Skipped
✅ nextjs-turbopack 27 0 0

✅ vercel-queue-hold

App Passed Failed Skipped
✅ nextjs-turbopack 4 0 0

✅ vercel-spec9

App Passed Failed Skipped
✅ nextjs-turbopack-node 198 0 9
✅ nextjs-turbopack-quickjs 197 0 10

✅ vercel-ws-transport

App Passed Failed Skipped
✅ example 171 0 36
✅ express 171 0 36
✅ nextjs-turbopack 199 0 8
✅ vite 171 0 36

📋 View full workflow run

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

📊 Workflow Benchmarks

commit 9384c7d · Tue, 17 Nov 2026 16:31:36 GMT · run logs

Backend: vercel · app: nextjs-turbopack

Metric Scenario Best (ms) P75 (ms) P90 (ms) P99 (ms) Samples
TTFS step 125 (-86%) 💚 326 🔴 (-76%) 💚 403 🔴 (-72%) 💚 555 (-75%) 💚 30
TTFS stream 150 (-88%) 💚 375 🔴 (-73%) 💚 426 🔴 (-70%) 💚 2895 🔴 (+100%) 🔻 30
TTFS hook + stream 294 (-80%) 💚 440 🔴 (-72%) 💚 522 🔴 (-67%) 💚 1041 🔴 (-40%) 💚 30
Fan-out TTFS Promise.all(100 steps) 292 (-10%) 545 (-1.1%) 565 (-31%) 💚 1752 (+7.6%) 10
Fan-out TTLS Promise.all(100 steps) 931 (-64%) 💚 4302 (+7.1%) 4407 (+8.9%) 5087 (-16%) 💚 10
STSO 1020 steps (inline) 70 (-7.9%) 109 (+14%) 131 (+12%) 226 (-14%) 1019
WO 1020 steps 110400 (+11%) 110400 (+11%) 110400 (+11%) 110400 (+11%) 1
📈 STSO distribution vs main (inline / queue-hop histograms)

1020 steps (inline)

Cumulative STSO time: main 98927ms → this run 110205ms (Δ +11278ms, +11%)

 50-100 ms  ███████████████┃████████  main 830  this 542  -288
100-150 ms  █████░░░░░░┃              main 158  this 420  +262
150-200 ms  ┃                         main  16  this  30   +14
200-250 ms  ┃                         main   4  this  21   +17
250-300 ms  ┃                         main   3  this   2    -1
300-350 ms  ┃                         main   2  this   2    +0
350-400 ms  ┃                         main   2  this   0    -2
400-450 ms  ┃                         main   1  this   0    -1
450-500 ms  ┃                         main   2  this   1    -1
500-550 ms  ┃                         main   1  this   0    -1
600-650 ms  ┃                         main   0  this   1    +1
ℹ️ Metric definitions & methodology

The collapsed STSO distribution section above buckets every step gap, split inline (same warm process — pure framework overhead) vs queue-hop (fresh process — dispatch, reinit, replay). █ = main, ┃ = this run, ░ = fill.

Best/P75/P90/P99 deltas compare against the most recent benchmark run on main at the time of this run. 🔻 flags a delta worse than +15%, 💚 one better than −15%.

Metrics — TTFS: time to first step body (in-deployment start() → first step body) · Fan-out TTFS: fan-out time to first step (in-deployment start() → first of the parallel step bodies to complete) · Fan-out TTLS: fan-out time to last step (in-deployment start() → last of the parallel step bodies to complete, i.e. when the Promise.all resolves) · STSO: step-to-step overhead (gap between consecutive step bodies) · WO: workflow overhead (whole-run time outside step bodies, in-deployment anchored)

Scenarios — step: one trivial no-op step, no stream; no hooks, so the run stays in turbo mode (in-process fast path) · stream: one streaming step; no hooks, so the run stays in turbo mode (in-process fast path) · hook + stream: registers a hook before one step, which exits turbo mode (dispatch path) · 1020 steps: 1020 trivial sequential steps; STSO is measured between consecutive steps in the given step ranges, and WO is the whole-run overhead outside step bodies · Promise.all(100 steps): 100 trivial no-op steps started together in a single Promise.all; Fan-out TTFS is the first of them to complete and Fan-out TTLS the last, both from the in-deployment clientStart, so their gap is the spread the runtime adds across the fan-out

🔴 marks a percentile over its target (within target is left unmarked). Targets (p75/p90/p99, ms) — TTFS 200/300/600

All timestamps are deployment-side; runs are triggered in-deployment, so the CI runner and api.vercel.com sit outside every measured window. TTFS = start() → first step body (includes dispatch + any cold start); Fan-out TTFS/TTLS = first/last step completion of one Promise.all from the same anchor (the gap is the runtime’s fan-out spread); STSO/WO between step bodies. Streaming delivery performance is measured in durabench.

Cold starts stay in the numbers (real bursty-workload latency, inflates P75+); Best is the warm floor.

@github-actions

Copy link
Copy Markdown
Contributor

Sim World

Simulated world deterministic testing for races. Traces

🟢 world-sim scenario book — 0 fail of 45 total
scenario outcome events virt replay violations
✅ smoke-no-steps completed 3 0ms ok 0
✅ smoke-one-step completed 5 0ms ok 0
✅ hook-at-step-started completed 9 0ms ok 0
✅ hook-at-step-completed completed 9 0ms ok 0
✅ hook-at-hook-created completed 9 0ms ok 0
✅ claim-hook-at-registration completed 9 0ms ok 0
✅ claim-hook-at-step-started completed 9 0ms ok 0
✅ deadline-hook-wins completed 6 1.0h ok 0
✅ deadline-expires completed 6 1.0h ok 0
✅ step-vs-timer-early-settlement completed 6 1.0h ok 0
✅ long-sleep completed 9 30.0d ok 0
✅ hook-never-arrives stalled 3 0ms skipped 0
✅ step-retries-twice completed 9 2.0s ok 0
✅ parallel-steps completed 7 0ms ok 0
✅ hook-on-execution-state completed 9 0ms ok 0
✅ peek-hook-before-branch completed 9 0ms ok 0
✅ peek-hook-after-branch completed 9 0ms ok 0
✅ peek-hook-at-registration completed 9 0ms ok 0
✅ race-hook-before-probe completed 9 0ms ok 0
✅ race-hook-after-probe completed 9 0ms ok 0
✅ race-duplicate-delivery completed 10 0ms ok 0
✅ attr-hook-before-step completed 9 0ms ok 0
✅ attr-hook-after-step completed 9 0ms ok 0
✅ attr-from-step-body completed 10 0ms ok 0
✅ fork-hook-after-timeout completed 11 1.0m ok 0
✅ fork-hook-before-timeout completed 11 1.0m ok 0
✅ count-hook-after-timeout completed 13 1.0m ok 0
✅ count-hook-before-timeout completed 15 1.0m ok 0
✅ stale-read-step-count-fork completed 15 1.0m ok 0
✅ stale-read-equal-step-counts completed 11 1.0m ok 0
✅ step-vs-step-fork completed 9 0ms ok 0
✅ step-vs-step-fork-fenced completed 9 1.0s ok 0
✅ fence-catches-benign-direction completed 9 1.0s ok 0
✅ run-ahead-fenced-overlap completed 10 1.0s ok 0
✅ in-flight-before-decision completed 15 1.0m ok 0
✅ in-flight-before-decision-counted completed 13 1.0m ok 0
✅ in-flight-after-decision completed 15 2.0m ok 0
✅ stale-read-step-count-fork-fenced completed 15 1.0m ok 0
✅ fork-hook-wins completed 10 1.0m ok 0
✅ fork-timeout-wins completed 10 1.0m ok 0
✅ unclaimed-payload-under-fork completed 14 1.0m ok 0
✅ claimed-payload-under-fork completed 14 1.0m ok 0
✅ writers-independent-step-bodies completed 9 0ms ok 0
✅ writers-scripted-tempo completed 9 0ms ok 0
✅ cancel-mid-step cancelled 6 0ms skipped 0

Full trace: world-sim.txt

@github-actions

Copy link
Copy Markdown
Contributor
Framework Flow route Step reg. Framework output
hono 306.2 KiB (±0) 124.0 KiB (±0) 2.39 MiB (±0)
nextjs-turbopack 397.8 KiB (±0) 491 B (±0) 1.13 MiB (±0)
About these numbers

Sizes are gzip; parentheses show the change against main.
Flow route and Step reg. gate this job, on raw bytes rather than the gzip shown, at max(2%, 50.0 KiB). Framework output is informational.

9384c7d · run

@TooTallNate TooTallNate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nothing blocking.

The fix is right. The new !self.in_module_level branch for Expr::Fn matches the nested arrow path: it hoists via push_nested_step_function, namespaces with record_nested_step_name, and collects closure vars in both modes. Step IDs line up between step and workflow output. Module-level function expressions still take the old path. Passing false for the lexical-this flag is correct for a regular function.

What I checked locally:

  • cargo test in transform/ passes, including step_id_consistency on the new fixture.
  • I ran extra probe fixtures (not committed) for a few edge cases:
    • arguments inside the step gets hoisted correctly.
    • this gets hoisted correctly, with no closure getter.
    • Same-named function-expression steps in a nested block get the ~1 suffix correctly (wf2/b / wf2/b~1), and this also works mixed with arrow steps.
  • CI and E2E are green.

Non-blocking follow-ups (both were already there before this PR, so they shouldn't hold it up):

  1. A named function expression that calls itself. In const fact = async function inner(k) { "use step"; return ... await inner(k - 1); }, inner gets collected as a closure variable. The workflow output then emits () => ({ inner }), and inner isn't in scope in the workflow body, so it throws a ReferenceError once the getter runs. The hoisted step function is also renamed (wf$fact), so the self-reference has nothing to bind to on the step side. The unbound form (return async function inner() { "use step"; ... inner() }) has the same problem on main. Nested function decl() {} self-recursion also gives () => ({ decl }). That one does resolve because of hoisting, but it's still an odd capture. It's worth a follow-up to leave a function expression's own name out of the closure collector (and keep it bound in the hoisted copy).
  2. No async check. The comment above this branch says "Validate that it's async", but nothing checks it. A non-async const f = function () { "use step" } inside a workflow compiles to a step without a diagnostic. The arrow path and the module-level path behave the same way, so this is a separate cleanup.

@TooTallNate
TooTallNate merged commit e6f5bc7 into main Nov 17, 2026
200 checks passed
@TooTallNate
TooTallNate deleted the codemod-for-steprun-to-use-step-migration-swc-named-fn-step branch November 17, 2026 17:48
@github-actions github-actions Bot mentioned this pull request Nov 17, 2026
github-actions Bot added a commit that referenced this pull request Nov 17, 2026
…able inside a function as a nested step (#5503)

A `"use step"` function expression bound to a variable inside a workflow
(or any other function) was compiled as a module-level step, so the run
failed when it reached it:

```ts
export async function receiptWorkflow(n: number, label: string) {
  'use workflow';
  const send = async function () {
    'use step';
    return `${label}:${n}`;
  };
  return send(); // Step "step//./workflows/receipt//send" is not registered
}
```

The arrow form (`const send = async () => { 'use step'; ... }`) and a
function declaration already worked.

**Cause:** in `visit_mut_var_decl`, the `Expr::Fn` step branch had no
nested-scope check, unlike the `Expr::Arrow` branch next to it. As a
result:

- step mode emitted a registration for a binding that doesn't exist at
module scope, so nothing was registered;
- workflow mode called the un-namespaced step ID (`…//send`) without a
closure-variable getter.

**Fix:** inside a function, this branch now takes the same path as the
arrow form. The step is hoisted and namespaced by the enclosing function
(`receiptWorkflow/send`), it gets the variables it captures, and the
original function is kept with the directive stripped for direct calls.
A step bound to a variable takes the variable's name, as it already did
at module scope and for arrows. Module-level function expressions are
unchanged.

- **New fixture** (`nested-step-function-expression`): named and
anonymous function expressions inside a workflow, one inside a plain
helper function, and a module-level control. The step and workflow
outputs agree on every step ID, which `step_id_consistency` checks. All
421 Rust tests pass, and existing fixture outputs are unchanged.
- **Runtime:** the vitest workbench runs a workflow with a named and an
anonymous function-expression step, both capturing workflow variables.
On the previous plugin build it fails with `Step
"step//./workflows/nested-step-ids//named" is not registered`; with this
change it passes. The full vitest workbench passes (77 tests, plus one
marked as an expected failure).
- **Spec:** `spec.md` lists the nested-step forms and how each is named.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Co-authored-by: Pranay Prakash <1797812+pranaygp@users.noreply.github.com>
Signed-off-by: Pranay Prakash <pranay.gp@gmail.com>
@github-actions

Copy link
Copy Markdown
Contributor

Backport PR opened against stable: #5509. Merge conflicts were resolved by AI — please review carefully. (backport job run)

TooTallNate pushed a commit that referenced this pull request Nov 17, 2026
… bound to a variable inside a function as a nested step (#5509)

Automated backport of #5503 to `stable` ([backport job
run](https://github.com/vercel/workflow/actions/runs/44140977209)).

**AI recommendation:** This fixes a bug in a feature `stable` already
has. A `"use step"` function expression bound to a variable inside a
workflow is compiled as a module-level step, so the run fails with "Step
... is not registered". The same un-scoped `Expr::Fn` branch in
`visit_mut_var_decl` exists on `stable`, which already supports nested
arrow steps and closure variables. The plugin code on `stable` has
diverged from `main` (different helper signatures and a `Client` mode),
so expect the cherry-pick to conflict and review it carefully.

Merge conflicts were resolved by AI ([opencode](https://opencode.ai)
with `anthropic/claude-opus-5.5`). **Please review the conflict
resolution carefully before merging.**

Signed-off-by: Pranay Prakash <pranay.gp@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Co-authored-by: Pranay Prakash <1797812+pranaygp@users.noreply.github.com>
@github-actions github-actions Bot mentioned this pull request Nov 17, 2026
pranaygp added a commit that referenced this pull request Nov 17, 2026
Now that a "use step" function expression bound to a variable compiles as a
nested step (#5503), drop the advice to use only arrow functions and
function declarations, and say how each form is named.

Co-Authored-By: Claude <noreply@anthropic.com>

Co-Authored-By: Pranay Prakash <1797812+pranaygp@users.noreply.github.com>

This branch was successfully deployed

1 active deployment
Preview – workflow-docs — 9384c7df Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants